<template>
    <div>
      <h2>部门表添加</h2>
      部门名称: <input type="text" v-model="name">
      <button @click="sub">添加</button>
    </div>
</template>

<script>
    export default {
        name: "AddDepartment",
        data(){
          return{
            name:'',
          }
        },
        methods:{
          sub(){
            // 1 模拟form表单
            let formdata=new FormData();

            // 2 将数据添加到表单中
            formdata.append('name',this.name);

            // 3 向后端发送数据
            this.axios({
              url:'http://127.0.0.1:8000/app01/department/',
              method:'post',
              data:formdata,
            }).then(res=>{
              alert(res.data.msg)
            })
          }
        }
    }
</script>

<style scoped>

</style>
